package com.wn.icloud.common.msg;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: zhq
 * @datetime: 2020/4/25 11:33
 * @description: TODO
 */
public enum  ObjectRestCode {

    /* 成功状态码 */
    SUCCESS(200, "成功"),

    /* 未知错误 */
    UNKNOWN_ERROR(-1,"未知错误"),
    FAILURE(301,"参数失效"),
    FAILURE_LIMIT(302,"请求频繁,请稍候再试"),
    SMS_FAILURE(303,"请求频繁,请稍候再试"),
    REGISTER_FAILURE(304,"用户已注册"),
    SMS_ERROR(305,"验证码错误"),
    SMS_OVER(306,"验证码已过期"),

    /* 参数错误：10001-19999 */
    PARAM_IS_INVALID(10001, "参数无效"),
    PARAM_IS_BLANK(10002, "参数为空"),
    PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
    PARAM_NOT_COMPLETE(10004, "参数缺失"),

    /* 用户错误：20001-29999*/
    USER_NOT_LOGGED_IN(20001, "用户未登录"),
    USER_LOGIN_ERROR(20002, "账号不存在或密码错误"),
    USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
    USER_NOT_EXIST(20004, "用户不存在"),
    USER_HAS_EXISTED(20005, "用户已存在"),
    USER_OLD_PASSWORD(20006, "原密码错误"),
    USER_LOGIN_CODE_ERROR(20007, "验证码错误"),
    USER_NOT_EXIST_GO_REGISTER(20008, "用户不存在,请先注册"),


    /* 业务错误：30001-39999 */
    SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "某业务出现问题"),

    /* 企业码业务错误 */
    ENTERPRISE_INFO_ERROR(31000,"企业码业务出现错误,请稍后重试"),
    /* 未找到企业信息，请稍后重试 */
    NOT_FOUND_ENTERPRISE_INFO_ERROR(31001,"未找到企业信息,请稍后重试!"),
    /* 保存企业信息出现未知错误,请检查数据格式，重试! */
    SAVE_ENTERPRISE_INFO_ERROR(31002,"保存企业信息出现未知错误,请检查数据格式，稍后重试!"),
    /* 维护用户和企业认证信息时出现未知错误，请稍后重试*/
    SAVE_LINK_USER_ENTERPRISE_INFO_ERROR(31002,"维护用户和企业认证信息时出现未知错误，请稍后重试!"),
    /* 查询企业工商信息失败 */
    FIND_BUSINESS_INFO_ERROR(31002,"根据企业信用代码未找到工商信息"),
    ENTERPRISE_CERT_ERROR(31003,"企业认证失败"),

    /* 系统错误：40001-49999 */
    SYSTEM_INNER_ERROR(40001, "系统繁忙，请稍后重试"),

    /* 数据错误：50001-599999 */
    RESULE_DATA_NONE(50001, "数据未找到"),
    DATA_IS_WRONG(50002, "数据有误"),
    DATA_ALREADY_EXISTED(50003, "数据已存在"),
    DATA_STATUS_STOP(50004, "数据状态已停用"),
    DATA_STATUS_START(50005, "数据状态已启用"),

    /* 接口错误：60001-69999 */
    INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),
    INTERFACE_OUTTER_INVOKE_ERROR(60002, "外部系统接口调用异常"),
    INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"),
    INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"),
    INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"),
    INTERFACE_EXCEED_LOAD(60006, "接口负载过高"),

    /* 权限错误：70001-79999 */
    PERMISSION_NO_ACCESS(70001, "无访问权限");

    private Integer code;

    private String message;

    ObjectRestCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer code() {
        return this.code;
    }

    public String message() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (ObjectRestCode item : ObjectRestCode.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ObjectRestCode item : ObjectRestCode.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }

    //校验重复的code值
    public static void main(String[] args) {
        ObjectRestCode[] ApiResultCodes = ObjectRestCode.values();
        List<Integer> codeList = new ArrayList<Integer>();
        for (ObjectRestCode ApiResultCode : ApiResultCodes) {
            if (codeList.contains(ApiResultCode.code)) {
                System.out.println(ApiResultCode.code);
            } else {
                codeList.add(ApiResultCode.code());
            }
        }
    }
}
